package multimedia;

import java.awt.Dimension;
import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Vector;

import magick.MagickException;
import magick.MagickImage;
import multimedia.model.DWT;
import multimedia.model.ModifiedImage;
import multimedia.model.colorspace.ColorspaceUtil;
import multimedia.model.quantize.MedianCut;
import multimedia.util.ProjectConstants;

/**
 * 
 */

/**
 * @author trigueros
 * 
 */
public class Driver
{

    /**
     * @param args
     * @throws MagickException
     * @throws FileNotFoundException 
     */
    public static void main( String[] args ) throws MagickException, FileNotFoundException
    {
//        // Create 2D Array
//        double[][] imagePixels = new double[model.getImageSize().height][model.getImageSize().width];
//        
//        // Populate 2D Array
//        for( int x = 0; x < model.getImageSize().width; x++ )
//            for( int y = 0; y < model.getImageSize().height; y++ )
//            {
//                imagePixels[y][x] = model.getImagePixelHolder().getPixelAt(x, y).getFirstComponent();
//            }
//        
//        /* First Part of Wavelet Transform */
//        RealMatrix modelMatrix = new Array2DRowRealMatrix(imagePixels);
//        RealMatrix haarMatrix = calculateHaar1DMatrix(model.getImageSize().height);
//        
//        // Perform multiplication of the Haar Matrix
//        modelMatrix = haarMatrix.multiply(modelMatrix);
//        
//        /* Second Part of Wavelet Transform */
//        haarMatrix = calculateHaar1DMatrix(model.getImageSize().width);
//        
//        // Calculate the transpose
//        haarMatrix = haarMatrix.transpose();
//        
//        // Perform multiplication of the Haar Matrix
//        modelMatrix = modelMatrix.multiply(haarMatrix);
//        
//        
//        // Calculated Matrix into a Colorspace Vector
//        Vector<ColorspaceInterface> newVector = new Vector<ColorspaceInterface>();
//        for( int x = 0; x < modelMatrix.getRowDimension(); x++ )
//            for( int y = 0; y < modelMatrix.getColumnDimension(); y++ )
//            {
//                newVector.add( new YIQ((float) modelMatrix.getEntry(x, y), 0.0f,0.0f));
//            }
//        
//        
//        // Setting the main image rgbVector
//        model.getImagePixelHolder().setRgbVector(newVector);
//        
        String imageName = "lena.png";
        System.out.println();
        ModifiedImage model = new ModifiedImage(ProjectConstants.IMAGE_DIR + imageName);
//        MagickImage magickImg = model.getMagickImage();
//        magickImg = magickImg.scaleImage(8, 8);
//        model.setMagickImage(magickImg);
//        model.setImageSize( new Dimension(8, 8));
//        model.selectRegion(new Point(0,0), new Point(8, 8));
//        model.writeToBinaryFile("lena8_8.RGB", model.getImagePixelHolder().toString());
        
        // Convert to YIQ
//        model.getImagePixelHolder().setRgbVector( ColorspaceUtil.ConvertToYIQ( model.getImagePixelHolder().getRgbVector() ) );
//        
//        DWT haarTransformer = new DWT(model);
//        haarTransformer.applyTransform();
//        System.out.println(haarTransformer.getIterationCount());
//        model.getImagePixelHolder().setRgbVector(haarTransformer.matrixToColorVector());
//        
//        // Convert back to RGB
//        model.getImagePixelHolder().setRgbVector( ColorspaceUtil.ConvertFromYIQ( model.getImagePixelHolder().getRgbVector() ) );
//        
//        model.writeBinaryToImage(imageName);
//        
//        haarTransformer.generateFileOutput("test1.txt", 0, 20);
//        MedianCut cut = new MedianCut(model);
//        cut.MedianCutAlgorithm();
        
        Vector<Double> test = new Vector<Double>();
        test.set(5, 5.0);
        
        
    }
    
//    public static RealMatrix calculateHaar1DMatrix(int dim)
//    {
//        RealMatrix haarMatrix = new Array2DRowRealMatrix(dim, dim);
//        
//        // Create the top part of the matrix, the one that calculates the average
//        for( int col = 0, row = 0; row < dim/2; col+=2 , row++)
//        {
//            haarMatrix.setEntry(row,col, 0.5);
//            haarMatrix.setEntry(row,col+1, 0.5);
//        }
//        
//        // Create the bottom part of the matrix, the one that calculates the differences
//        for( int col = 0, row = dim/2; row < dim; col+=2 , row++)
//        {
//            haarMatrix.setEntry(row,col, -0.5);  
//            haarMatrix.setEntry(row,col+1, 0.5);
//        }
//        
//        return haarMatrix;
//    }
    
}

















